package com.qtyx.nms.ui.base

import android.app.Activity
import com.ldd.base.ui.fragment.BaseLddFragment
import com.ldd.base.util.ActivityManageUtil
import com.qtyx.nms.custom.LoadingPopup
import com.qtyx.nms.mvp.base.BasePresenter
import com.qtyx.nms.mvp.base.BaseView
import com.qtyx.nms.ui.activity.LoginActivity
/**
 * 集成网络请求
 */
abstract class BaseMVPFragment<P : BasePresenter> :BaseLddFragment(),BaseView {

    protected lateinit var presenter: P
    protected abstract fun createPresenter(): P

    override fun initSetting() {
        presenter = createPresenter()
    }

    private var loadingPopup: LoadingPopup? = null
    override fun showLoading() {
        if (loadingPopup == null) {
            loadingPopup = LoadingPopup(mContext as Activity)
        }
        activity?.window?.decorView?.post { loadingPopup?.show() }
    }

    override fun hideLoading() {
        activity?.window?.decorView?.postDelayed({ loadingPopup?.dismiss() }, 300)
    }

    override fun onError(msg: String) {
        showToast(msg)
    }

    override fun onTokenShiXiao(msg: String) {
        showToast(msg)
        ActivityManageUtil.finishAllActivity()
        startActivityCustom(LoginActivity::class.java)
    }

    override fun onDestroy() {
        super.onDestroy()
        presenter.detachView()
    }

}